package cn.com.nes.site.module.service.newmall;

import cn.com.nes.common.util.DBUtils;
import cn.com.nes.common.util.MapUtil;
import cn.com.nes.site.entity.DataReq;
import cn.com.nes.site.entity.PageData;
import cn.com.nes.site.module.dao.newmall.NewmallDaoImpl;
import com.alibaba.fastjson2.JSONObject;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.sql.Connection;
import java.sql.SQLException;

@Service
public class NewmallService {

    @Resource
    private NewmallDaoImpl impl;

    public PageData getAgentAndShopkey(DataReq req) throws SQLException {
        Connection conn = null ;
        PageData res = new PageData() ;
        try {
            conn = DBUtils.getJNDIDBConn();
            res = impl.getAgentAndShopkey(conn,req);
        }catch (Exception e) {
            e.printStackTrace();
        }finally {
            if(conn!=null) {
                conn.rollback();
                conn.close();
            }
        }
        return res ;
    }

    public PageData checkVerCodeIncreaseTime(String phone,String vercode) throws SQLException {
        Connection conn = null ;
        PageData res = new PageData() ;
        try {
            conn = DBUtils.getJNDIDBConn();
            res = impl.checkVerCodeIncreaseTime(phone,vercode);
        }catch (Exception e) {
            e.printStackTrace();
        }finally {
            if(conn!=null) {
                conn.rollback();
                conn.close();
            }
        }
        return res ;
    }

    public PageData login(DataReq req) throws SQLException {
        Connection conn = null ;
        PageData res = new PageData() ;
        try {
            conn = DBUtils.getJNDIDBConn();
            res = impl.login(conn,req);
        }catch (Exception e) {
            e.printStackTrace();
        }finally {
            if(conn!=null) {
                conn.rollback();
                conn.close();
            }
        }
        return res ;
    }

    public PageData getShopCompanyList(DataReq req)  {
        String xzqhmc=(String)req.getReqData().get("xzqhmc");
        if(!StringUtils.isEmpty(xzqhmc)){//传了行政区划就自查经纬度
            JSONObject adressObj = MapUtil.getGeoByAddress(xzqhmc);
            if(adressObj!=null){
                String lng=adressObj.getString("lng");
                String lat=adressObj.getString("lat");
                req.getReqData().put("longitude",lng);
                req.getReqData().put("latitude",lat);
            }
        }
        return impl.getShopCompanyList(req);
    }

    public PageData getBrowseCompanyList(DataReq req)  {
        String xzqhmc=(String)req.getReqData().get("xzqhmc");
        if(!StringUtils.isEmpty(xzqhmc)){//传了行政区划就自查经纬度
            JSONObject adressObj = MapUtil.getGeoByAddress(xzqhmc);
            if(adressObj!=null){
                String lng=adressObj.getString("lng");
                String lat=adressObj.getString("lat");
                req.getReqData().put("longitude",lng);
                req.getReqData().put("latitude",lat);
            }
        }
        return impl.getBrowseCompanyList(req);
    }

    public PageData getShopCompanyById(DataReq req)  {
        return impl.getShopCompanyById(req);
    }

    public PageData userPraise(DataReq req) throws Exception {
        return impl.userPraise(req);
    }

    public PageData userComment(DataReq req) throws Exception {
        return impl.userComment(req);
    }

    public PageData deleteUserComment(DataReq req) throws Exception {
        return impl.deleteUserComment(req);
    }

    public PageData getUserComment(DataReq req) throws Exception {
        return impl.getUserComment(req);
    }

    public PageData getUserCommentSecond(DataReq req) throws Exception {
        return impl.getUserCommentSecond(req);
    }

    public PageData getProductRecommend(DataReq req)  {
        return impl.getProductRecommend(req);
    }

    public PageData getProductList(DataReq req)  {
        return impl.getProductList(req);
    }

    public PageData addBrowse(DataReq req) throws Exception {
        return impl.addBrowse(req);
    }

    public PageData getProductDetails(DataReq req)  {
        return impl.getProductDetails(req);
    }

    public PageData addRelation(DataReq req) throws Exception {
        return impl.addRelation(req);
    }

    public PageData getRelationList(DataReq req)  {
        return impl.getRelationList(req);
    }

    public PageData getUserDals(DataReq req)  {
        return impl.getUserDals(req);
    }

    public PageData getAreaCodeByLocation(DataReq req) throws Exception {
        return impl.getAreaCodeByLocation(req);
    }

    public PageData getNextXzqh(DataReq req) throws Exception {
        return impl.getNextXzqh(req);
    }
}
